<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Jayrock HelloWorld Test Page</title>
        <script type="text/javascript" src="js/jayrock/json.js"></script>
        <script type="text/javascript" src="HelloWorld.ashx?proxy&v=2"></script>
        <script language="JavaScript" src="js/jsunit/app/jsUnitCore.js"></script>
        <script type="text/javascript">                
            function error (message, stackTrace) {    
                alert("Error Communicating with Server!");  
                alert("Message:" + message);  
                alert("Location:" + location);  
             }
            function channel_error(o) {
                var payload = JSON.eval(o);
                error(payload.error.message,payload.error.stackTrace);
             }
             
        </script>    
        <script type="text/javascript" src="js/dojo/dojo.js"></script>
        <script type="text/javascript">        
            dojo.require("dojo.event.*");
            dojo.require("dojo.io.*");
            dojo.require("dojo.json");
            function dojo_channel_error (type, data, evt) {
                var p = JSON.eval(evt.responseText); 
                var message = p.error.message;
                var location = p.error.stackTrace;               
                alert("Error communicating with server!");  
                alert("Message: " + message); 
                alert("Location: " + location);
            }  
            function dojo_channel(call)
            {
	            var bindArgs = {
		            url: call.url+'?rpc',
		            error: function(type, data, evt) { channel_error(evt.responseText) },
		            method: "POST",
		            mimetype: "text/json",
		            handle: function(type, data) { call.callback(data) },                    
		            postContent: dojo.json.serialize(call.request)
	        };
	            var req = dojo.io.bind(bindArgs);
	            dojo.event
	            return req;
            }
        </script>         
        <script type="text/javascript" src="js/prototype/prototype.js"></script>          
        <script type="text/javascript">                 
         function proto_channel(call)
         {
            return new Ajax.Request(
                call.url, {
                    postBody : "JSON-RPC=" +
                        encodeURIComponent(JSON.stringify(call.request)),
                        onSuccess : function (xhr) {
                            var response = JSON.eval(xhr.responseText);
                            if (response.error != null)
                                window.status = response.error.message;
                            else
                            call.callback(response.result);
                        }
             });
         }          
        </script>         
        <script type="text/javascript" src="http://yui.yahooapis.com/2.2.0/build/yahoo/yahoo-min.js"></script>
        <script type="text/javascript" src="http://yui.yahooapis.com/2.2.0/build/utilities/utilities-min.js"></script>        
        <script type="text/javascript">
            function yui_async(url, request, callback)
            {   
                return YAHOO.util.Connect.asyncRequest("POST", url,
                {
                    success : function(o)
                    {
                        if (typeof(callback) !== "function")
                            return;
                        var payload = JSON.eval(o.responseText)           
                        if (payload.error) {
                            error( payload.error.message, payload.error.stackTrack );
                            return;
                      }
                      callback(payload);},
                    failure : function(o)
                    {
                        channel_error(o.responseText);
                    }},
                    "JSON-RPC=" + encodeURIComponent(JSON.stringify(request)));
            }            
            function yui_channel(call)
            {
                return yui_async(call.url, call.request, call.callback);
            }
        </script>
        <script type="text/javascript">

            /* Need to use proxy without v=2 for this one. */
            function v1_test_hello_synch() {
                var s = new PhoneBook();
                var greetings = s.greetings();
                assertEquals("Welcome to Jayrock!",greetings);                
            }              
            function assert_greetings(type, data, evt) {        
                assertNull(data.result);        
                assertEquals("Welcome to Jayrocks!",data.result);        
            }        
            function test_dojo_channel() {
                HelloWorld.rpc.greetings(assert_greetings).call(dojo_channel);
            }            
            function test_proto_channel() {
                HelloWorld.rpc.greetings(assert_greetings).call(proto_channel);
            }
            function test_yui_channel() {
                HelloWorld.rpc.greetings(assert_greetings).call(yui_channel);
            }
        </script>
        <script type="text/javascript">
            window.onload = function() 
            {
                HelloWorld.rpc.greetings(function(data) { 
                   alert("dojo async:" + data.result)                 
                }).call(dojo_channel);

                HelloWorld.rpc.greetings(function(data) {
                    alert("proto async:" + data.result)
                }).call(proto_channel);                

                HelloWorld.rpc.greetings(function(data) {
                    alert("yui async:" + data.result)
                }).call(yui_channel);                
            }                
        </script>
    </head>
    <body>       
        <p>This page tests the HelloWorld service with Jayrock, Dojo, Prototype, and YUI.</p>        
        <p>NOTE: The Prototype channel is not working at this time.</p>    
    </body>
</html>
